#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'test'
exit 1
}

while getopts  ":p:f:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

b450k_no_name=$data_path/methy/beta/b450k.no_name.txt
names=$data_path/methy/beta/b450k.names.txt

nf_all=`awk '{print NF; exit 0}' $b450k_no_name`
echo $nf_all

x=(20000 30000 40000 50000 60000 70000 80000 90000 100000)

for i in ${x[@]}; do
    cv_pre2.py $nf_all $i $out_prefix.nf.$i.txt
    dos2unix $out_prefix.nf.$i.txt
    
    j=0
    for nf in `cat $out_prefix.nf.$i.txt`; do
        ((j+=1))
        cut -f $nf $b450k_no_name > $out_prefix.b450k.sub.${i}.${j}.txt
    done
    
    paste $names $out_prefix.b450k.sub.$i.*.txt > $out_prefix.b450k.sub.$i.txt
    rm $out_prefix.b450k.sub.$i.*.txt
done

. $cmd_done